window.addEventListener("load", function () {

    // 轮播图1的实现

    // 左右两箭头的隐藏
    let lf = this.document.querySelector('.bannerjian1')
    let rt = this.document.querySelector('.bannerjian2')
    let banner = this.document.querySelector('.banner')
    let banner_width = banner.offsetWidth;
    let ul = this.document.querySelector(".imgList")
    

    banner.addEventListener('mouseenter', function () {
        lf.style.display = "block";
        rt.style.display = "block";
        clearInterval(timer)
        timer = null
    })
    banner.addEventListener('mouseleave', function () {
        lf.style.display = "none";
        rt.style.display = "none";
        timer = setInterval(function () {
        rt.click();
        },3500)
    })

    // 点击右侧按钮事件
    let num1 = 0
    rt.addEventListener('click', function () {
        if (num1 === ul.children.length-1) {
            ul.style.left = 0;
            num1 = 0;
        }
        num1++;
        animate(ul, -num1 * banner_width)
    })

    // 点击左侧按钮事件
    let num2 = 0
    lf.addEventListener('click', function () {
        if (num2 === 0) {
            num2 = ul.children.length-1;
            ul.style.left = -num2 * banner_width + 'px';
        }
        num2--;
        animate(ul, -num2 * banner_width)
    })

    // 自动播放轮番图
    let timer = setInterval(function () {
        rt.click();
    }, 3500)
    

    // 轮番图2的实现
    let left = this.document.querySelector('.injian1')
    let right = this.document.querySelector('.injian2')
    let inbook = this.document.querySelector('.inbook')
    let inbook_width = inbook.offsetWidth;
    let ull = this.document.querySelector(".inimg")

    inbook.addEventListener('mouseenter', function () {
        left.style.display = "block";
        right.style.display = "block";
        clearInterval(timer1)
        timer1 = null
    })
    inbook.addEventListener('mouseleave', function () {
        left.style.display = "none";
        right.style.display = "none";
        timer1 = setInterval(function () {
        rt.click();
        },3000)
    })

    // 点击右侧按钮事件
    let num3 = 0
    right.addEventListener('click', function () {
        if (num3 === ull.children.length-1) {
            ull.style.left = 0;
            num3 = 0;
        }
        num3++;
        animate(ull, -num3 * inbook_width)
    })

    // 点击左侧按钮事件
    let num4 = 0
    left.addEventListener('click', function () {
        if (num4 === 0) {
            num4 = ull.children.length-1;
            ull.style.left = -num4 * inbook_width + 'px';
        }
        num4--;
        animate(ull, -num4 * inbook_width)
    })

    // 自动播放
    let timer1 = setInterval(function () {
        right.click();
    }, 3000)
})